//
//  TBBLEBase.h
//  TBSDK
//
//  Created by nexgo on 2017/10/27.
//  Copyright © 2017年 truth. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TBBLEManager.h"
#import "TBBLEBaseAction.h"

#import "TBBLEWriteCharacterAction.h"

#import "TBBLEReadCharacterAction.h"

#import "TBBLEReadRssiAction.h"

#import "TBBLEEnNotifyAction.h"

// 连接回调
@interface TBBLEBaseCB : NSObject

@property (nonatomic,copy) void(^onConnect)(TBErrorCode*);  // 连接结果回调

@property (nonatomic,copy) void(^onRetryConnect)(int);  // 尝试重连

@property (nonatomic,copy) void(^onDisConnect)(TBErrorCode*);  // 被动断开连接

@property (nonatomic,copy) void(^onManualDisConnect)(TBErrorCode*);  // 主动断开连接

@property (nonatomic,copy) void(^onCharactChanged)(CBCharacteristic*, NSData*);  // 数据改变

@end

// 设置监听结果回调
@interface EnCharacterListenCB : NSObject

@property (nonatomic,copy) void(^onEnCharacterListen)(TBErrorCode*);  // 连接结果回调

@end

typedef void(^VoidCB)(void);


@interface TBBLEBase : NSObject

- (instancetype)init:(TBBLEManager*)managerTmp;

/**
 开始连接
 @param device 需要连接的设备
 @param retryTimes 尝试重连次数
 @param cb 回调
 @return 执行结果
 */
-(TBErrorCode*)connect:(TBBLEDevice*)device retryTimes:(int)retryTimes cb:(TBBLEBaseCB*)cb;

/**
 断开连接
 */
-(TBErrorCode*)disConnect;

/**
 查看连接状态
 */
-(BOOL)isConnected;

/**
 获取所有服务
 @return 服务列表
 */
-(NSArray<CBService*>*)getAllServices;

/**
 通过UUID，获取指定服务
 @param uuid 需要获取服务的uuid
 @return 执行结果
 */
-(CBService*)getServiceByUuid:(NSString*)uuid;

/**
 获取指定character
 @param servicesUUID 对应服务的UUID
 @param characterUUID 对应特征值的UUID
 @return 执行结果
 */
-(CBCharacteristic*)getCharacterByUuid:(NSString*)servicesUUID characterUuid:(NSString*)characterUUID;

/**
 使能特征值的监听
 @param character 对应服务
 @param enable 使能开关
 @return 执行结果
 */
-(TBErrorCode*)enCharacterListen:(CBCharacteristic*)character enable:(BOOL)enable;

/**
 添加任务
 @param action 添加的任务
 @return 执行结果
 */
-(TBErrorCode*)addAction:(TBBLEBaseAction*)action;

@end
